import { reqGetBannerListData, reqGetCategoryListData, reqGetFloorsListData } from "@/api";

// home 模块的小仓库
const state = {
    // 三级导航数据
    categoryList:[],
    // 轮播图数据
    bannerList:[],
    // 楼层数据
    floorsList:[]
};
const actions = {
    // 调用接口获取三级导航数据
    async getCategoryList(context){
        const res = await reqGetCategoryListData();
        // 操作mutations
        if(res.code===200){
            context.commit('CATEGORYLIST',res.data)
        }
    },

    // 调用接口获取轮播图数据
    async getBannerList({commit}){
        const res = await reqGetBannerListData();
        if(res.code===200){
            commit('BANNERLIST',res.data)
        }
    },

    // 获取楼层数据
    async getFloorsListData(context){
        const res = await reqGetFloorsListData();
        if(res.code === 200){
            context.commit('GETFLOORSLIST',res.data)
        }
    }
};
const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList
    },

    BANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },

    GETFLOORSLIST(state,floorsList){
        state.floorsList = floorsList
    }
};
const getters = {};

export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters
}